package br.com.pontoclass.primes;

import java.math.BigInteger;
import java.util.logging.Level;
import java.util.logging.Logger;

import br.com.pontoclass.patterns.SimpleNumberListener;
import br.com.pontoclass.primes.util.MathLogicUtil;


public class SimpleNumbersDifferencePrinterSimpleNumberListener implements SimpleNumberListener {
    
    private static final Logger LOGGER = Logger.getLogger(SimpleNumbersDifferencePrinterSimpleNumberListener.class.getName());
    private BigInteger last    = BigInteger.ZERO;
    private BigInteger lastSum = BigInteger.ZERO;
    private String base;
    
    public SimpleNumbersDifferencePrinterSimpleNumberListener(String base) {
        this.base = base;
        
    }
    
    @Override
    public void onAddSimple(BigInteger simple) {
        simple = MathLogicUtil.convertFrom(new BigInteger(base), simple);
        String out;
        BigInteger help;
        System.out.println(out=String.format("simple [%s] diff [%s]", simple, ((help=simple.add(last)).subtract(lastSum).toString())));
        LOGGER.log(Level.INFO, out);
        last  = simple;
        lastSum = help;
    }
}